﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 算法基本功.算法._0_数组._1_双指针.快慢指针
{
    internal class 移除元素
    {
        public int RemoveElement(int[] nums, int val)
        {
            if(nums.Length == 0 )  return 0;

            //慢指针负责记录满足条件的个数 快指针负责遍历数组
            int slow = 0,fast = 0;
            while (fast < nums.Length) {

                if (nums[fast] != val) {
                    //移除value
                    nums[slow] = nums[fast];
                    slow++;
                }
                fast++;
            }

            //返回边界是有效个数 比如 [0,1,2,2,3,0] val =2 则返回4
            return slow;
        }
    }
}
